package com.example.web;

import com.example.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * ClassName:IndexController
 * Description:
 *
 * @date:2020/3/10 10:43
 * @author:蛙课网
 */
@Controller
public class IndexController {

//若controller没提供的参数，但在html显示  会500
    @RequestMapping(value = "/test1")
    public String index(Model model) {
        model.addAttribute("data","SpringBoot Thymeleaf");
//        User user = new User();
//        model.addAttribute("user",user);
        return "index";
    }

    /**
     * Controller传对象及属性
     * 网页传参数给Controller！！！！！！！！传递
     * @return
     */
    @RequestMapping(value = "/test2")
    public ModelAndView index2() {
        ModelAndView mv = new ModelAndView();
        User asdf = new User(1, "asdf", 31);
        mv.addObject("user",asdf);
        mv.addObject("data","SpringBoot Thymeleaf");
        mv.setViewName("index");
        return mv;
    }

    /**
     * 网页1.3传参数给Controller！！！！！！！！！！接收
     * @return
     */
    @RequestMapping(value = "/test3")
    public ModelAndView index3() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("kong");
        return mv;
    }

    /**
     * photo
     * @return
     */
    @RequestMapping(value = "/test4")
    public ModelAndView index4() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index2");
        return mv;
    }



    /**
     * from
     * @return
     */
    @RequestMapping(value = "/form")
    public ModelAndView index5() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("kong");
        return mv;
    }
}
